/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vzone.structs;

import java.io.Serializable;
import java.util.UUID;

/**
 *商品可序列化基类
 * @author Kingpro
 */
public class BaseObject implements Serializable
{

    /**
     * 物品的UUID
     */
    public UUID IdUuid;
    /**
     * 物品名称
     */
    public String NameS;
    /**
     * 物品价格
     */
    public double SaleMoneyD;
    /**
     * 物品数量
     */
    public int CountI;

    /**
     * 构造函数 自动生成UUID 其余默认初始化
     */
    public BaseObject()
    {
	this(null, 0, 0);
    }

    /**
     * 构造函数 从一个对象赋值
     * @param bobj 需要复制的对象
     */
    public BaseObject(BaseObject bobj)
    {
	IdUuid = bobj.IdUuid;
	NameS = bobj.NameS;
	SaleMoneyD = bobj.SaleMoneyD;
	CountI = bobj.CountI;
    }

    /**
     * 构造函数 初始化所有值
     * @param idUuid UUID
     * @param nameS 商品名称
     * @param saleMoneyD 商品价格
     * @param countI 商品数量
     */
    public BaseObject(UUID idUuid, String nameS, double saleMoneyD, int countI)
    {
	IdUuid = idUuid;
	NameS = nameS;
	SaleMoneyD = saleMoneyD;
	CountI = countI;
    }

    /**
     * 构造函数 自动生成UUID
     * @param nameS 商品名称
     * @param saleMoneyD 商品价格
     * @param countI 商品数量
     */
    public BaseObject(String nameS, double saleMoneyD, int countI)
    {
	this(UUID.randomUUID(), nameS, saleMoneyD, countI);
    }

    /**
     * 构造函数 从字符串创建UUID
     * @param idUuidS UUID字符串
     * @param nameS 商品名称
     * @param saleMoneyD 商品价格
     * @param countI 商品数量
     */
    public BaseObject(String idUuidS, String nameS, double saleMoneyD, int countI)
    {
	this(UUID.fromString(idUuidS), nameS, saleMoneyD, countI);
    }

    /**
     * 重写equals
     * @param o 要比较的对象
     * @return 如果两个对象有相同的值 则true 否则false
     */
    @Override
    public boolean equals(Object o)
    {
	if (!(o instanceof BaseObject))
	{
	    return false;
	}
	BaseObject baseObject = (BaseObject) o;
	return IdUuid == baseObject.IdUuid && NameS.equals(baseObject.NameS) && SaleMoneyD == baseObject.SaleMoneyD && CountI == baseObject.CountI;
    }

    /**
     * 重写hashcode
     * @return hashcode
     */
    @Override
    public int hashCode()
    {
	int hash = 5;
	hash = 79 * hash + (this.IdUuid != null ? this.IdUuid.hashCode() : 0);
	hash = 79 * hash + (this.NameS != null ? this.NameS.hashCode() : 0);
	hash = 79 * hash + (int) (Double.doubleToLongBits(this.SaleMoneyD) ^ (Double.doubleToLongBits(this.SaleMoneyD) >>> 32));
	hash = 79 * hash + this.CountI;
	return hash;
    }

    /**
     * 复制对象本身(进行对象赋值操作时请使用此方法)
     * @return 拥有对象本身所有值的新对象
     */
    public BaseObject Clone()
    {
	return new BaseObject(IdUuid, NameS, SaleMoneyD, CountI);
    }
}
